@include('admin.header')

<link href="/static/admin/css/myadmin.css"  rel="stylesheet" type="text/css">

<div class="wrap">
    <div class="margin-bottom-20">
        <form action="{{url('merchant/pos_order_list')}}" method="get">
            <div class="grey-nav">
                <span>搜索</span>
                <div class="pull-right">
                    <button name="" id="search" class="btn btn-info user_search" type="submit"><i class="Hui-iconfont"></i> 搜索</button>
                    <button class="btn btn-primary" type="reset">重置</button>
                    <button class="btn btn-success toggle" type="button">隐藏/显示</button>
                </div>
            </div>
            <div id="search-area">
                <div class="cl pd-5 bg-1 bk-gray mt-20">
                    订单类型:
                    <select name="order_type">
                        <option value="">全部</option>
                        <option value="1">线下</option>
                        <option value="2">报单</option>
                    </select>
                    下单时间:
                    <span class="datep"><input class="datainp" id="dateinfo1" type="text" placeholder="开始时间" name="s_time" style="width:200px;height: 20px;margin-top: 10px;"  readonly value="{{isset($_GET['s_time'])?$_GET['s_time']:'2015-01-01 00:00:00'}}"></span>
                    <span class="datep"><input class="datainp" id="dateinfo2" type="text" placeholder="结束时间" name="e_time" style="width:200px;height: 20px;margin-top: 10px;"  readonly value="{{isset($_GET['e_time'])?$_GET['e_time']:'2055-01-01 00:00:00'}}"></span>
                </div>
                <div class="cl pd-5 bg-1 bk-gray mt-20">
                    关键词搜索
                    <select name="keyname">
                        <option value="">请选择</option>
                        <option value="order_no" @if(Request::get('keyname')=='order_no') selected @endif>订单ID</option>
                        <option value="mobile" @if(Request::get('keyname')=='mobile') selected @endif>买家手机号</option>
                    </select>
                    <input type="text" name="keyval" class="high-input" value="{{Request::get('keyval')}}">
                </div>
            </div>
        </form>
    </div>
    <div class="grey-nav">
        <span>列表</span>
        <div class="pull-right">
            <button class="btn btn-success" id="excel">导出为Excel</button>
        </div>
    </div>
    <div>
        <div class="row">
            <div class="col-12">
                <span>排序：</span>
                <select name="sort">
                    <option value="asc" @if(Request::get('sort')=='asc') selected @endif>下单时间升序</option>
                    <option value="desc" @if(Request::get('sort')=='desc') selected @endif>下单时间降序</option>
                </select>
                <span>每页显示：</span>
                <select name="pagesize">
                    <option value="10" @if(Request::get('pagesize')==10) selected @endif>10</option>
                    <option value="25" @if(Request::get('pagesize')==25) selected @endif>25</option>
                    <option value="50" @if(Request::get('pagesize')==50) selected @endif>50</option>
                    <option value="100" @if(Request::get('pagesize')==100) selected @endif>100</option>
                    <option value="500" @if(Request::get('pagesize')==500) selected @endif>500</option>
                    <option value="1000" @if(Request::get('pagesize')==1000) selected @endif>1000</option>
                </select>
                <span>条</span>
            </div>
        </div>
    </div>
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th class="text-center"><input name="id-all" type="checkbox" value=""></th>
                <th class="text-center">序号</th>
                <th class="text-center">订单ID</th>
                <th class="text-center">订单类型</th>
                <th class="text-center">买家手机号</th>
                <th class="text-center">下单时间</th>
                <th class="text-center">支付总金额</th>
                <th class="text-center">
                    <div>让利金额</div>
                    <div style="color: #999999;">（存款金额）</div>
                </th>
                <th class="text-center">手续费</th>
                <th class="text-center">应结算金额</th>
            </tr>
            </thead>
            <tbody>
                @foreach($data as $key=>$item)
                <tr>
                    <td class="text-center">
                        <input name="" type="checkbox" class="details_id" value="{{$item->id}}">
                    </td>
                    <td class="text-center">{{$key+1}}</td>
                    <td class="text-center">{{$item->order_no}}</td>
                    <td class="text-center">
                        @if($item->order_type==1)
                            线下
                        @elseif($item->order_type==2)
                            报单
                        @else
                            未定义
                        @endif
                    </td>
                    <td class="text-center">{{$item->mobile}}</td>
                    <td class="text-center">{{$item->create_time}}</td>
                    <td class="text-center">
                        {{floatval($item->amount)}}
                    </td>
                    <td class="text-center">
                        @if($item->order_type==1)
                            <div>{{floatval($item->deposit)}}</div>
                            <div style="color: #999999;">（<span>{{floatval($item->deposit)}}</span>）</div>
                        @elseif($item->order_type==2)
                            0
                        @else
                            未定义
                        @endif
                    </td>
                    <td class="text-center">{{floatval($item->amount*0.006)}}</td>
                    @if($item->order_type==1)
                        <td class="text-center">{{floatval($item->amount-floatval($item->deposit))-floatval($item->amount)*0.006}}</td>
                    @elseif($item->order_type==2)
                        <td class="text-center">{{floatval($item->amount)-floatval($item->amount)*0.006}}</td>
                    @else
                        未定义
                    @endif
                </tr>
                @endforeach
            </tbody>
        </table>
        <!-- 分页 -->
        @if (!empty($data))
            <div class="page_list">
                {{$data->appends(Request::input())->links()}}
            </div>
        @endif

</div>
<script src="/static/js/common.js"></script>
<script src="/static/js/H-ui.min.js"></script>
<script>
    //数组Unique
    Array.prototype.unique = function(){
        var res = [];
        var json = {};
        for(var i = 0; i < this.length; i++){
            if(!json[this[i]]){
                res.push(this[i]);
                json[this[i]] = 1;
            }
        }
        return res;
    };

    //订单详情
    $('body').on('click','.view',function(){
        //获取参数
        var details_id = $(this).attr('data-details-id');
        if(!details_id){
            layer.msg("子订单ID非法");
            return false;
        }
        open_iframe_layer('/settlement/order_detail?details_id='+details_id);
    });

    //时间插件初始化
    laydate.render({
        elem: '#dateinfo1'
        ,type: 'datetime'
    });
    laydate.render({
        elem: '#dateinfo2'
        ,type: 'datetime'
    });

    //选择排序
    $("select[name=sort]").on('change',function () {
        window.location.href=(setUrlParam(window.location.href,'sort',this.value));
    });

    //每页数量
    $("select[name=pagesize]").on('change',function () {
        window.location.href=(setUrlParam(window.location.href,'pagesize',this.value));
    });

    //设置url中参数值
    function setUrlParam(location,name,value) {
        var url = location;
        var splitIndex = url.indexOf("?") + 1;
        var paramStr = url.substr(splitIndex, url.length);
        var newUrl = url.substr(0, splitIndex);
        // - if exist , replace
        var arr = paramStr.split('&');
        for (var i = 0; i < arr.length; i++) {
            var kv = arr[i].split('=');
            if (kv[0] == name) {
                newUrl += kv[0] + "=" + value;
            } else {
                if (kv[1] != undefined) {
                    newUrl += kv[0] + "=" + kv[1];
                }
            }
            if (i != arr.length - 1) {
                newUrl += "&";
            }
        }
        // - if new, add
        if (newUrl.indexOf(name) < 0) {
            newUrl += splitIndex == 0 ? "?" + name + "=" + value : "&" + name + "=" + value;
        }
        return newUrl;
    }

    /**
     * 切换隐藏
     */
    $(".toggle").on('click',function () {
        if(sessionStorage.displayType==1 || typeof sessionStorage.displayType=='undefined'){
            document.getElementById('search-area').style.display='none';
            sessionStorage.displayType=0;
        }else{
            document.getElementById('search-area').style.display='block';
            sessionStorage.displayType=1;
        }
    });
    if(sessionStorage.displayType==='0'){
        document.getElementById('search-area').style.display='none';
    }

    //导出excel
    $('#excel').click(function(){
        var str='';
        //拼接要结算的字段
        $('.details_id:checked').each(function(index){
            str+=$(this).val()+','
        });
        str=str.substr(0,str.length-1);
        if(str==''){
            alert('请勾选订单');
            return false;
        }else{
            var url=window.location.href;
            url=(setUrlParam(url,'details_list',str));
            location.href=setUrlParam(url,'export','true');
        }
    });

</script>